home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OTSAMPLE.ZIP / playsmp.doc < prev    next >
Text File  |  1996-07-10  |  8KB  |  168 lines

  1.  
  2.                      - THE OUTLAW TRIAD DEMO-SERIES -
  3.  
  4. ───────────────────────────────■ PART VIII ■──────────────────────────────────
  5.  
  6.                          Written by : Vulture/OT
  7.                          Code in    : Pascal/Asm
  8.                          Topic      : Samples
  9.  
  10. ──────────────────────────────■ Introduction ■────────────────────────────────
  11.  
  12.  Welcome to the Outlaw Triad demo-series! In these series we will be talking
  13.  about programming demo-effects in either pascal or assembler. Theory behind
  14.  the effects shall be discussed while a full sourcecode is also provided.
  15.  This time we will talk about something completely different, sound-coding!
  16.  We will create a basic .RAW sound player using the soundblaster (sorry, no
  17.  GUS). Sound will be played using DMA transfers, just like modplayers. Enjoy!
  18.  
  19. ─────────────────────────────────■ Theory ■───────────────────────────────────
  20.  
  21.  Notes: In this example I will use the most basic soundcard and that's
  22.  the soundblaster 2.0 (is 1.0 still alive?). Reason for this is that
  23.  I'm the lucky owner of such a device :-) and have absolutely no money
  24.  to buy a better card.
  25.  
  26.  Allright! Let's start by talking about some soundblaster basics such
  27.  as port adresses and writing and reading from the card. Fundamental
  28.  things like that cannot be done any other way like described below.
  29.  
  30.  The soundblaster can be programmed through 4 ports. These are:
  31.  
  32.    Reset                        2x6h
  33.    Read data                    2xAh
  34.    Write command/data output    2xCh
  35.    Write buffer status input    2xCh
  36.    Data available               2xEh
  37.  
  38.  The x is 1 for base address 210h, 2 for 220h ∙∙∙ and 6 for 260h.
  39.  
  40.  Now, before you can program the DSP, you will have to reset it. The reset
  41.  takes around a 100 micro-seconds so if the reset takes longer than that,
  42.  you can assume an error has occured and abort the program.
  43.  
  44.    - Write a 1 to the RESET port (2x6h)
  45.    - Wait for 3 micro-seconds
  46.    - Write a 0 to the RESET port (2x6h)
  47.    - Read the byte from the DATA AVAILABLE (2xEh) port until bit 7 = 1
  48.    - Poll for a ready byte (AAh) from the READ DATA port (2xAh)
  49.  
  50.  Ok, now the soundblaster can be programmed. Here's how to write a byte
  51.  to the card:
  52.  
  53.    - Read the WRITE BUFFER STATUS port until bit 7 equals 0
  54.    - Write value to the WRITE COMMAND/DATA port
  55.  
  56.  And how to read from it:
  57.  
  58.    - Read the DATA AVAILABLE port (2xEh) until bit 7 = 1
  59.    - Read data from the READ DATA port (2xAh)
  60.  
  61.  There! It should be fairly easy to write some procedures which perform
  62.  these tasks. Take a look at the source to see how it can be done.
  63.  
  64.  Ok, you understand the basics? Good! Now we are going to play a sample
  65.  (raw sound data) through the soundblaster. We need to setup the DMA and
  66.  soundblaster ports for output of raw data. The procedure for playing raw
  67.  data using DMA transfers is as follows:
  68.  
  69.    1. Load sound data into memory
  70.    2. Setup the DMA chip for the tranfer
  71.    3. Set the DSP TIME_CONSTANT to the sampling rate
  72.    4. Write DMA_TYPE_VALUE value to the DSP
  73.    5. Write DATA_LENGTH to the DSP (2 bytes, LSB first) where
  74.       DATA_LENGTH = number of bytes to send + 1
  75.  
  76.  Let's take a look at this in detail.
  77.  
  78.  1. Simple. Just get the required memory using the GETMEM procedure and
  79.     load the data using a BLOCKREAD command.
  80.  
  81.  2. We will be using DMA channel 1 for transfering the sound data to the
  82.     soundblaster. Here's how to setup the DMA chip for the transfer:
  83.  
  84.       - Calculate 20 bit address of the memory buffer you are using
  85.         like this: Segment * 16 + Offset
  86.       - Send value 05h to port 0Ah (mask off channel 1)
  87.       - Send value 00h to port 0Ch (clear the internal DMA flip/flop)
  88.       - Send value 49h to port 0Bh (playback) or
  89.                    45h to port 0Bh (recording)
  90.       - Write LSB (bits 0 - 7) of the 20 bit memory address to port 02h
  91.       - Write MSB (bits 8 - 15) of the 20 bit memory address to port 02h
  92.       - Write Page (bits 16 -> 19) of the 20 bit memory address to port 83h
  93.       - Send LSB of DATA_LENGTH to port 03h
  94.       - Send MSB of DATA_LENGTH to port 03h
  95.       - Send value 01h to port 0Ah (enable channel 1)
  96.  
  97.     I've used assembler to do most of this stuff but it isn't very hard to
  98.     convert it to Pascal or whatever language you use.
  99.  
  100.  3. Setting the frequency of the sample must be done by calculating a certain
  101.     time constant with: 256 - 1000000 / frequency. After you've done this,
  102.     you write the value to the soundblaster by writing value 40h to the card
  103.     immidiately followed by the time constant.
  104.     Note: for frequencies between 22 Khz - 44Khz, use the following formula:
  105.           (MSB of) 65536 - (256000000 / frequency)
  106.  
  107.  4. Various types of DMA transfers are provided. Here's a list which shows
  108.     them.
  109.  
  110.       ┌───────────────┬────────────────────┬───────────────────────┐
  111.       │DMA_TYPE_VALUE │ Description        │    Frequency Range    │
  112.       ├───────────────┼────────────────────┼───────────────────────┤
  113.       │    14h        │ 8 bit              │    4KHz -> 23 KHz     │
  114.       │    74h        │ 4 bit ADPCM        │    4KHz -> 12 KHz     │
  115.       │    75h        │ 4 bit ADPCM with   │    4KHz -> 12 KHz     │
  116.       │               │ reference byte     │                       │
  117.       │    76h        │ 2.6 bit ADPCM      │    4KHz -> 13 KHz     │
  118.       │    77h        │ 2.6 bit ADPCM with │    4KHz -> 13 KHz     │
  119.       │               │ reference byte     │                       │
  120.       │    16h        │ 2 bit ADPCM        │    4KHz -> 11 KHz     │
  121.       │    17h        │ 2 bit ADPCM with   │    4KHz -> 11 KHz     │
  122.       │               │ reference byte     │                       │
  123.       └───────────────┴────────────────────┴───────────────────────┘
  124.  
  125.     In this example we are transfering 8 bit samples so we simply write
  126.     14h to the soundblaster.
  127.  
  128.  5. Just write the low byte of the data length followed by the high
  129.     byte and you're done. Remember to increase the data length by 1.
  130.  
  131.  Well, that's all there is to it. Immediately after you've done these steps,
  132.  output will start and the sample will be played. It isn't very hard to code
  133.  just because you simply follow a set of basic rules. However, it's important
  134.  to implement this stuff correctly because these routines are the basics of
  135.  soundblaster programming.
  136.  
  137.  Ok, this is all for now. Happy coding!
  138.  
  139.      -Vulture/Outlaw Triad-
  140.  
  141. ───────────────────────────────■ Distro Sites ■───────────────────────────────
  142.  
  143.  Call our distrobution sites! All our releases are available at:
  144.  
  145.   BlueNose      World HQ          +31 (0)345-619401
  146.   The Force     Distrosite        +31 (0)36-5346967    More distros wanted!
  147.   Bugs'R'Us     Distrosite        +31 (0)252-686092    (preferably outside
  148.   ShockWave     South African HQ  +27 (011)888-6345     of the Netherlands)
  149.   Society HQ    United States HQ  +1  (518)465-6721
  150.  
  151.  Also check the major FTP sites for Outlaw Triad productions.
  152.  
  153. ──────────────────────────────────■ Contact ■─────────────────────────────────
  154.  
  155.  Want to contact Outlaw Triad for some reason? You can reach us at our
  156.  distrosites in Holland. Or if you have e-mail access, mail us:
  157.  
  158.    Vulture   (coder/pr)   comma400@tem.nhl.nl
  159.  
  160.  Our internet homepage:
  161.  
  162.    http://www.tem.nhl.nl/~comma400/vulture.html
  163.  
  164.  These internet adresses should be valid at least till june 1997.
  165.  
  166. ──────────────────────────────────────────────────────────────────────────────
  167.  
  168.                     Quote: 43.3% of statistics are useless